﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace GameWP
{
    public class UpgradeScreen : GameScreen
    {
#region Properties
        private Texture2D _background;
        public Texture2D Background
        {
            get { return _background; }
            set { _background = value; }
        }

        private UpgradeGeneralComponent _upgradeGeneralComponent;
        private UpgradeLuffyComponent _upgradeLuffyComponent;
        private UpgradeSkillComponent _upgradeSkillComponent;
        private UpgradeMemberComponent _upgradeMemberComponent;

#endregion

#region  Initilation
        public UpgradeScreen(Game game, MainGame mainGame, SpriteBatch spriteBatch, 
            Texture2D background, SpriteFont menuFont, SpriteFont textFont, SpriteFont minitextFont,
            Texture2D textureUpLevel, List<Texture2D> listIconAHero)
            : base(game, mainGame, spriteBatch)
        {
            _game = game;
            _mainGame = mainGame;
            _spriteBatch = spriteBatch;
            _background = background;


            // Init component
            _upgradeGeneralComponent = new UpgradeGeneralComponent(_game, menuFont, textFont, _spriteBatch);
            Components.Add(_upgradeGeneralComponent);
                //Event su kien click cua button item menu click
                for (int i = 0; i < _upgradeGeneralComponent.ListItemMenu.Count; i++)
                    _upgradeGeneralComponent.ListItemMenu[i].Selected += new Button.IsSelected(ItemMenu_Selected);
            _upgradeLuffyComponent = new UpgradeLuffyComponent(_game,textFont,_spriteBatch,textureUpLevel);
            Components.Add(_upgradeLuffyComponent);
            _upgradeSkillComponent = new UpgradeSkillComponent(_game, textFont,minitextFont, _spriteBatch);
            _upgradeMemberComponent = new UpgradeMemberComponent(_game, listIconAHero, textFont, minitextFont, _spriteBatch);
        }       
#endregion

#region Methods
        void ItemMenu_Selected(int input)
        {
            if (input != 0 && input != 1)
            {
                _upgradeGeneralComponent.SetColorTabActive(input);
                Components.RemoveAt(1);
            }
            switch (input)
            {
                case 0: _mainGame.ShowScreen(0); break;
                case 1: _mainGame.ShowScreen(4); break;    //Nut Next, goi toi man hinh chon thanh vien tran danh
                case 2: //kich hoat component skill ( tab luffy )
                    Components.Add(_upgradeLuffyComponent);
                    break;
                case 3: // tab skill
                    Components.Add(_upgradeSkillComponent);
                    break;
                case 4: // tab member
                    Components.Add(_upgradeMemberComponent);
                    break;
            }
        }

        public override void ResetScreen(int input)
        {
            SaveGameData _saveGameData = new SaveGameData();
            _saveGameData._AHeroHave = new List<int>();

            _saveGameData._hp = ManagerGame.luffy.Hp;
            _saveGameData._mana = ManagerGame.luffy.Mana;
            _saveGameData._dam = ManagerGame.luffy.Damage;
            _saveGameData._balance = ManagerGame.luffy.Balance;
            _saveGameData._level = ManagerGame.luffy.Level;
            _saveGameData._levelSkill = ManagerGame.luffy.LevelSkill;
            _saveGameData._levelScreen = ManagerGame.luffy.LevelScreen;
            _saveGameData._AHeroHave = ManagerGame.luffy.ListAHeroHave;

            ManagerGame.managerSaveLoad.SaveGame(_saveGameData);
        }
#endregion

#region Update & Draw
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            _spriteBatch.Begin();
            _spriteBatch.Draw(_background, Vector2.Zero, Color.White);
            base.Draw(gameTime);
            _spriteBatch.End();
        }
#endregion
    }
}
